from time import sleep

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By


@pytest.fixture(scope='session', autouse=True)
def driver():
    opt = webdriver.ChromeOptions()
    opt.add_experimental_option('w3c', False)
    driver = webdriver.Chrome(chrome_options=opt)
    driver.implicitly_wait(5)
    driver.get('http://litemall.hogwarts.ceshiren.com/#/login?redirect=%2Fdashboard')
    driver.maximize_window()
    sleep(2)

    # 登录
    driver.find_element(By.NAME, "username").clear()
    driver.find_element(By.NAME, "username").send_keys('admin123')
    driver.find_element(By.NAME, "password").clear()
    driver.find_element(By.NAME, "password").send_keys('admin123')
    driver.find_element(By.XPATH, "//*[@type='button']").click()
    sleep(2)

    yield driver
    driver.quit()